// console.log('this is mainjs')// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// 全局依赖
console.log('test2')
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/index'
import ElementUI from 'element-ui'
// import 'element-ui/lib/theme-default/index.css'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios' // todo 为什么没有改成wsloan的
import echarts from 'echarts'
import 'echarts/chart/line'
import 'echarts/chart/pie'
import 'echarts/component/title'
import 'echarts/component/grid'
import 'echarts/component/tooltip'
import 'echarts/component/legend'
import 'echarts/component/axis'
import 'babel-polyfill'
// websocket
import './config/myws'
import './config/websocket'

// 聊天室
import './js/jquery-1.8.3.min'
import './styles/images/style.scss'
import './styles/chat.scss'
import './styles/drag.scss'

// 正式
const url = "http://report.wsloan.com:8888/css/"
// 测试
//const url = "http://192.168.3.26:8285/"
// dcz
// const url = "http://192.168.3.26:6326/css/"
//const url = "http://192.168.22.36:8085/css/"   
//const url ="http://192.168.3.26:8285/"    
// wd
// const url = "http://192.168.0.140:8080/css/"

console.log('测试------12:15 2.8 service')
window.path = url
// 注释不要删除
// let get = (_this,{api,data,isLoading=true},baseUrl) => {
//   let innerUrl = url
//   if(baseUrl !== undefined){
//     innerUrl = baseUrl
//   }
//   if (isLoading) {
//     _this.$vux.loading.show({
//       text: 'Loading'
//      })
//   }
//   return _this.$ajax({
//     url:innerUrl+api,
//     data,
//     error: () => {
//       this.$warn('系统1 '+ api +' 错误')
//     },
//     success: ()=>{
//       if (isLoading) _this.$vux.loading.hide();
//     }
//   })
// }
// let post = (_this,{api,data,isLoading=true},baseUrl) => {
//   let innerUrl = url
//   if(baseUrl !== undefined){
//     innerUrl = baseUrl
//   }
//   if (isLoading) {
//     _this.$vux.loading.show({
//       text: 'Loading'
//      })
//   }
//   return _this.$ajax({
//     url:innerUrl+api,
//     data,
//     error: () => {
//       this.$warn('系统 '+ api +' 错误')
//     },
//     methods: 'post',
//     success: ()=>{
//       if (isLoading) _this.$vux.loading.hide();
//     }
//   })
// }

// Vue.prototype.$get = get
// Vue.prototype.$post = post
console.log('wb')
Vue.prototype.$api = wsloan.isTest ? '//192.168.3.26:6326/css' : '//report.wsloan.com:8888/css'
let initAjax = (method,token) => {
  return (_this,{api,data,isLoading=true},baseUrl) => {
    let innerUrl = url
    let headers = token ? {Authorization:token} : null
    if (baseUrl !== undefined) {
      innerUrl = baseUrl
    }
    if (isLoading) {
      _this.$vux.loading.show({
        text: 'Loading'
      })
    }
    return _this.$ajax({
      url: innerUrl + api,
      method,
      headers,
      data,
      success: () => {
        if (isLoading) _this.$vux.loading.hide();
      },
    })
  }
}
window.initAjax = initAjax
Vue.prototype.$get = initAjax('get')
Vue.prototype.$post = initAjax('post')
var Echarts = require('echarts')
Vue.prototype.$echarts = Echarts

import {AlertPlugin, ConfirmPlugin, ToastPlugin,LoadingPlugin } from 'vux'

import WSLOAN from '@wsloan/wsloan/src/entries/app.js'

Vue.config.productionTip = false
Vue.prototype.$http = axios

window.Vue = Vue

Vue.use(ElementUI)
Vue.use(LoadingPlugin)
Vue.use(WSLOAN, {
  AlertPlugin, ConfirmPlugin, ToastPlugin
})

// 重新构造ajax[ 增添headers ]
let ajax = function(option){
  let {url,method,headers = null,data,success} = option
  let config = {
    
    url,
    method,
  }
  // 判断请求头
  if(headers){
    Object.assign(config,{headers})
  }
  // 根据请求方法设置请求参数
  method.toLowerCase() === 'get' ? Object.assign(config,{params:data}) : Object.assign(config,{data})

  let promise = axios(config)
  if(success && typeof success === 'function'){
    promise.then(res => success(res))
  }
  return promise
}
Vue.prototype.$ajax = ajax
//

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: {
    App
  }
})
